package com.taxi.management.login;

import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.taxi.management.entity.UserEntity;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class UserUtils {
    public static Map<String, UserEntity> userMap = new HashMap<>();
    public static Map<UserEntity,String> tokenMap = new HashMap<>();
    public static String save(UserEntity user){
        try {
            String old = tokenMap.get(user);
            if (old != null) {
                tokenMap.remove(user);
                userMap.remove(old);
            }
            String uuid = UUID.randomUUID().toString();
            userMap.put(uuid, user);
            tokenMap.put(user, uuid);
            return uuid;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public static UserEntity get(String token){
        return userMap.get(token);
    }
}
